package com.dgshanger.sanhxiaofeisc.mvp.presenter

import com.dgshanger.sanhxiaofeisc.entity.CodePaySettingEntity
import com.dgshanger.sanhxiaofeisc.mvp.contract.CodePaySettingContract
import com.dgshanger.sanhxiaofeisc.mvp.model.CodePaySettingModel
import com.xx.baseuilibrary.mvp.BaseMvpPresenter
import com.xx.baseutilslibrary.network.rx.XxBaseHttpObserver

/**
 * Created by JacobHHH on 2018/4/20.
 */
class CodePaySettingPresenter : BaseMvpPresenter<CodePaySettingContract.Model, CodePaySettingContract.View>(), CodePaySettingContract.Presenter {

    override fun saveCodePaySettingStatus(pay_set_type: String?, pay_set_wallet_rate: String?
                                          , pay_set_integral_rate: String?) {

        getModel().saveCodePaySettingStatus(pay_set_type,pay_set_wallet_rate,pay_set_integral_rate
                , object : XxBaseHttpObserver<Any>(){
            override fun onCompleted(msg: String?, entity: Any?) {

            }

            override fun onError(error: String?) {
                getView()?.showToast(error)
            }

            override fun onStart() {
                getView()?.showLoadingDialog()
            }

            override fun onFinish() {
                getView()?.dismissLoadingDialog()
            }

        })
    }

    override fun loadData(isRefresh: Boolean) {
        getModel().loadData(object : XxBaseHttpObserver<CodePaySettingEntity>(){
            override fun onCompleted(msg: String?, entity: CodePaySettingEntity?) {
                getView()?.setData(entity)
            }

            override fun onError(error: String?) {
                getView()?.showToast(error)
                getView()?.showError(Throwable(error),isRefresh)
            }

            override fun onStart() {

            }

            override fun onFinish() {
                getView()?.dismissLoadingDialog()
            }

        })
    }

    override fun createModel(): CodePaySettingContract.Model = CodePaySettingModel()
}